package demo;


import demo.standard.Context;
import demo.standard.NonTerminalExpression;
import demo.standard.TerminalExpression;

import java.util.Arrays;
import java.util.List;

public class ClientForStandard {
    private final static List<String> typeList = Arrays.asList("String", "Long", "Double", "Boolean");
    private final static List<String> nameList = Arrays.asList("a", "b", "c", "d", "e");

    public static void main(String[] args) {

        isValid(new Context("String a"));
        isValid(new Context("Long b"));
        isValid(new Context("string a"));
        isValid(new Context("Long @"));
        isValid(new Context("Boolean c"));
    }


    public static boolean isValid(Context context) {

        TerminalExpression typeExpression = new TerminalExpression(typeList);
        TerminalExpression nameExpression = new TerminalExpression(nameList);
        NonTerminalExpression expression = new NonTerminalExpression(typeExpression, nameExpression);
        boolean result = expression.interpreter(context);

        System.out.println("解析语句：" + context.getData());
        System.out.println("是否符合语法：" + result + "\n");
        return result;
    }
}